package com.xiaofeng.action;

import java.io.IOException;
import java.util.Map;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;

import com.xiaofeng.common.Const;

import cn.dsna.util.images.ValidateCode;




@Controller("valiCodeAction")
public class ValiCodeAction implements SessionAware,ServletResponseAware,ServletRequestAware{
	private Map<String, Object> sessionMap;
	@Override
	public void setSession(Map<String, Object> sessionMap) {
		// TODO Auto-generated method stub
		this.sessionMap = sessionMap;
	}
	private HttpServletRequest request;
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	private HttpServletResponse response;
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
		
	}
	public void code() throws IOException {
		System.out.println("进来了");
		ValidateCode code = new ValidateCode(100,30,4,10);
		String str = code.getCode();//获取验证码的数据  
		//request.setAttribute("code", str);
		//session.setAttribute("code", str);
		//生成验证码
		//sessionMap.put("code", str);
		HttpSession session = request.getSession();
		session.setAttribute("code", str);

		System.out.println(code);
		code.write(response.getOutputStream());
		
	}
	

}
